import {getCode} from './request.js'
(async function(){
    const {user_name,qrCode,savePicBtn,back2index,moreBook,mybooks,daytime}={
        user_name: document.getElementById('user_name'),
        qrCode: document.getElementById('qrCode'),
        savePicBtn: document.getElementById('savePicBtn'),
        back2index: document.getElementById('back2index'),
        moreBook: document.getElementById('moreBook'),
        mybooks: document.getElementById('mybooks'),
        daytime:document.getElementById('daytime')
    }
    //请求二维码
    let dataGetCode = {
        token : sessionStorage.getItem('token'),
        id : sessionStorage.getItem('id')
    }
    // getCode 用来请求二维码
    const resReport = await getCode(dataGetCode)
    console.log(resReport)
    qrCode.src = resReport.data.data
    user_name.innerHTML = sessionStorage.getItem('name')

    daytime.innerHTML = `${sessionStorage.getItem('choosDate')}的${sessionStorage.getItem('choosTime')}`
    console.log(daytime.innerHTML)

    // //截屏
    // 参数1：你要截取的节点
    // 参数2：具体的一些这个插件的配置
    new html2canvas(document.body, {
        backgroundColor: "transparent",
        allowTaint: true,
        useCORS: true 
    }).then(canvas => {
        // 当截图成功了，就会触发的成功回调
        // canvas.toDataURL() 获取截图的地址
        // 设置download属性即可下载

        //a标签download法
        // let name = new Date().getTime();
        // savePicBtn.href = canvas.toDataURL()
        // savePicBtn.download = name+'.png'\

        //适配手机a标签down'load兼容属性不好的截图效果 
        const navi = document.querySelector('#navi')
        const reunfil = document.querySelector('#reunfil ')
        savePicBtn.addEventListener('click',function(){      
            reunfil.innerHTML+= `<div id="savePic_filter">截图中</div>` 
            const savePic_filter = document.querySelector('#savePic_filter')
            savePic_filter.addEventListener('animationend',()=>{
                navi.firstElementChild.nextElementSibling.src = canvas.toDataURL()
                navi.classList.remove('scale0')
            })
        })
        navi.addEventListener('click',function(){
            navi.classList.add('scale0')
        })
    }); 




    back2index.addEventListener('click',function(){
        location.href = '../index.html'
    })
    moreBook.addEventListener('click',function(){
        location.href = './book.html'
    })
    mybooks.addEventListener('click',function(){
        location.href = './mybook.html'
    })
})()